<?php
/**
 * @package techniv-bb.tcnv-fw
 * @version 0.0.1
 * @copyright © Techniv 2011
 * @license <http://opensource.org/licenses/gpl-3.0.html> GNU General Public License - 3.0
 */


/**
 * @author Techniv
 */
class TcnvInterceptor {
	
	private $name;
	/** @var ReflectionAnnotatedMethod */
	private $intercepting_method;


	public function __construct($name) {
		$this->name = $name;
		$this->intercepting_method = array();
	}


	/** @param ReflectionMethod $method */
	function add_intercepting_method($method){
		$this->intercepting_method[] = $method;
	}	
	/** @param ReflectionMethod $methods */
	function add_intercepting_methods($methods){
		if(!is_array($methods)){
			$this->add_intercepting_method($methods);
			return;
		}
		$this->intercepting_method = array_merge($this->intercepting_method,$methods);
	}	
	
	
	function fire_intercept(&$args = null, $condition = null){
		foreach ($this->intercepting_method as $value) {
			$method = $value['method'];
			$annotation_value = $value['annotation_value'];
			if(isset($condition) && $condition != $annotation_value){
				continue;
			}
			
			$method instanceof ReflectionAnnotatedMethod;
			$class = $method->class;
			$class = new ReflectionAnnotatedClass($class) ;
			$method->invoke($class->newInstance(), $this->name ,&$args);
		}
	}
	
	public static 
		$postrow_name = "PostRowInterceptor",
		$blocassigne_name = "BlocAssignementInterceptor"
	;
}

?>
